home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 135_01.zip / V.C < prev    next >
Text File  |  1993-06-10  |  4KB  |  120 lines

  1. /*
  2.     v.c---test bed for very long integer package
  3.     written in assembler for BDSc.  To include:
  4.  
  5.  
  6.     FUNCTIONS WRITTEN:
  7.  
  8.         s    string
  9.         n    integer
  10.         s1,s2    string
  11.  
  12.     incrl(s)    increment a string by one.
  13.     decrl(s)    decrement a string by one.
  14.     saddl(s,n)    short add, add an integer to a string.
  15.     ssubl(s,n)    short subtract, subtract an integer from a string.
  16.     addl(s1,s2)    add string one to string two.
  17.     subl(s1,s2)    subtract string two from string one.
  18.     smull(s,n)    short multiply, multiply a string by an integer.
  19.     sdivl(s,n)    short divide, divide a string by an integer.
  20.     sdivlr(s,n)    short divide rounded, as above with rounded result.
  21.     smodl(s,n)    short modulus, return remainder of a string divided by
  22.             an integer.
  23.     mull(s1,s2)    multiply string one by string two.
  24.     divl(s1,s2)    divide string one by string two.
  25.     divrl(s1,s2)    divide string one by string two with rounded result.
  26.     modl(s1,s2)    return remainder of string one divided by string two.
  27.     sqrtl(s)    square root of a string.
  28.     sqrtlr(s)    square root of a string rounded.
  29.     facl(s)        string factorial.
  30.     spowl(s,n)    return string to the power of an integer.
  31.     powl(s1,s2)    return string one to the power of string two.
  32.     gcdl(s1,s2)    greatest common divisor of string one and string two.
  33.     sgcd(s,n)    greatest common divisor of a string and an integer.
  34.     lcm(s1,s2)    least common multiple of string one and string two.
  35.     slcm(s,n)    least common multiple of a string and an integer.
  36.     randl(n)    random number generator.  if n == 0 return r(memory)
  37.             else return r(1).
  38.     maxl(s1,s2)    floor function, return smaller of s1 and s2.
  39.     minl(s1,s2)    ceiling function, return larger of s1 and s2.
  40.     absl(s)        return absolute value of a string.
  41.  
  42.     iszero(s)    boolean truth function, test s == 0?
  43.     isneg(s)    boolean truth function, test s < 0?
  44.     ispos(s)    boolean truth function, test s >= 0?
  45.     iseven(s)    boolean    truth function, test mod(s,2)=0?
  46.     isequal(s1,s2)    boolean truth function, test s1 == s2?
  47.     sisequal(s,n)    boolean truth function, test s == n?
  48.     isltl(s1,s2)    boolean truth function, test s1 < s2?
  49.     sisltl(s,n)    boolean truth function, test s < n?
  50.     isgtl(s1,s2)    boolean truth function, test s1 > s2?
  51.     sisgtl(s,n)    boolean truth function, test s > n?
  52.  
  53.  
  54.     Current version limits are 2^1024 bits of precision.
  55.     Usage is pretty much the obvious, except that I would ovoid
  56.     complex function calls.  They should work since vli.crl has its
  57.     own storage for all calls but use your own discretion.  You 
  58.     should be aware that the limit on the size of a string that
  59.     printf() can handle is MAXLINE in bdscio.h.  I've changed my
  60.     version to #define MAXLINE 600 and recompiled stdlib1.c and
  61.     stdlib2.c, then used clib to build a new deff.crl.  This seems
  62.     to take care of the problem.  This test program provides some
  63.     examples of vli.crl usage, so hack away.
  64.  
  65.     Hugh S. Myers
  66.  
  67.     build:
  68.         n>cc v
  69.         n>clink v vli math
  70.  
  71.     3/12/84
  72.     4/9/84
  73.  
  74. */
  75.  
  76. #include <bdscio.h>
  77. #define MAX 256
  78.  
  79. main()
  80. {
  81.     char strbuf1[MAX], strbuf2[MAX];
  82.     char *s1, *s2;
  83.     int n;
  84.  
  85.     s1=strbuf1;
  86.     s2=strbuf2;
  87.     n=1;
  88.  
  89.     puts("usage: a:v<cr>\n");
  90.     puts("       ?s1 <some number><cr>\n");
  91.     puts("       ?s2 <some number><cr>\n");
  92.  
  93.     forever {
  94.         printf("?s1 ");
  95.         getline(s1,MAX);
  96.         printf("?s2 ");
  97.         getline(s2,MAX);
  98.  
  99.         printf("the sum of s1 and s2 is %s\n",addl(s1,s2));
  100.         printf("the difference of s1 and s2 is %s\n",subl(s1,s2));
  101.         printf("the product s1 and s2 is %s\n",mull(s1,s2));
  102.         printf("the quotient of s1\\s2 is %s\n",divl(s1,s2));
  103.         printf("the modulus of s1\\s2 is %s\n",modl(s1,s2));
  104.         printf("the s1 to the power of the s2 is %s\n",powl(s1,s2));
  105.         printf("the GCD s1 and s2 is %s\n",gcdl(s1,s2));
  106.         printf("the LCM s1 and s2 is %s\n",lcml(s1,s2));
  107.         printf("a random number is %s\n",randl(n));
  108.         if(n)
  109.             n = 0; /* first call to randl n should = 1
  110.                   there after n should = 0 */
  111.  
  112.         printf("s1 factorial is %s\n",facl(s1));
  113.         printf("the smaller of s1 and s2 is %s\n",minl(s1,s2));
  114.         printf("the larger of s1 and s2 is %s\n",maxl(s1,s2));
  115.         printf("the absolute value of the difference of s1 and s2 is %s\n",absl(subl(s1,s2)));
  116.         printf("s1 > s2 is %d\n",isgtl(s1,s2));
  117.         printf("s1 < s2 is %d\n",isltl(s1,s2));
  118.     }
  119. }
  120.